UserScore=require('../models/wx.js');
function wxController(url){

}
wxController.in_page=function(req,res){
    UserScore.get_in_arr(function(err,user){

        res.render('wx_game',{
            titlel:'主页fdsaf',
            result:user
        })
    })
}
wxController.post_score=function(req,res){
    var name=req.body.user_name;
    var score=req.body.score;
    var new_score=new UserScore({
        name:name,
        score:score
    })
    new_score.get(new_score.name,function(err,user){
        if (err) {
            req.flash('error', err);
            return res.redirect('/in_page');
        }
        if (user) {
            new_score.update(name,score,function(err,user){
                console.log('fdsafasgasgsad=========================');
            });
            return res.redirect('/in_page');
        }
        new_score.save(function(err, user){
            if (err) {
                req.flash('error', err);
                return res.redirect('/in_page');
            }
            req.session.user = user;
            req.flash('success', '成功存入!');
            res.redirect('/in_page');
        })
    })

}
module.exports=wxController;